//
//  LS_StatusToolBar.swift
//  weibo
//
//  Created by 罗李苏 on 16/5/25.
//  Copyright © 2016年 Apple. All rights reserved.


//微博的底部视图

import UIKit
import SnapKit
class LS_StatusToolBar: UIView {
    //添加视图模型属性
    var statusViewModel: LS_StatueViewModel?{
        didSet{
            repostBtn.setTitle(statusViewModel?.repostsText, forState: .Normal)
            commentBtn.setTitle(statusViewModel?.commentsText, forState: .Normal)
            ohYeahBtn.setTitle(statusViewModel?.attitudesText, forState: .Normal)
        
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //MARK:添加子视图到父视图 并设置约束
    private func setupUI(){
        addChildBtn(repostBtn, title: "转发", imageName: "timeline_icon_retweet")
        addChildBtn(commentBtn, title: "评论", imageName: "timeline_icon_comment")
        addChildBtn(ohYeahBtn, title: "点赞", imageName: "timeline_icon_like")
        
    //子视图评分父视图
        repostBtn.snp_makeConstraints { (make) in
            make.top.left.bottom.equalTo(self)
        }
        
        commentBtn.snp_makeConstraints { (make) in
            make.top.equalTo(repostBtn.snp_top)
            make.left.equalTo(repostBtn.snp_right)
            make.width.equalTo(repostBtn.snp_width)
        }
        
        ohYeahBtn.snp_makeConstraints { (make) in
            make.top.equalTo(commentBtn)
            make.left.equalTo(commentBtn.snp_right)
            make.right.equalTo(self)
            make.width.equalTo(repostBtn.snp_width)
        }
        //MARK:添加竖线
        let view1 = lineView()
        let view2 = lineView()
        addSubview(view1)
        addSubview(view2)

        let width = 1 / UIScreen.mainScreen().scale
        view1.snp_makeConstraints { (make) in
            make.left.equalTo(commentBtn.snp_left)
            make.centerY.equalTo(self.snp_centerY)
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.width.equalTo(width)
        }
        view2.snp_makeConstraints { (make) in
            make.left.equalTo(commentBtn.snp_right)
            make.centerY.equalTo(self.snp_centerY)
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.width.equalTo(width)
        }

    
    }
    //MARK:创建竖细线的方法
    private func lineView() -> UIView{
        let line = UIView()
        //设置背景颜色
        line.backgroundColor = UIColor.purpleColor()
        
        return line
    }
    //MARK:创建按钮的方法
    private func addChildBtn(btn: UIButton, title: String, imageName: String){
        
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.setTitle(title, forState: .Normal)
        //设置文字大小
        btn.titleLabel?.font = UIFont.systemFontOfSize(10)
        //设置图片
        btn.setImage(UIImage(named: imageName), forState: .Normal)
        //设置背景图片
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        //自适应的大小
        btn.sizeToFit()
        //添加到父视图
        self.addSubview(btn)
    }
    //MARK:懒加载子控件
    private lazy var repostBtn: UIButton = UIButton()
    private lazy var commentBtn: UIButton = UIButton()
    private lazy var ohYeahBtn: UIButton = UIButton()

}
